﻿using System;
using HMEngine.HMCameras;
using HMEngine.HMComponents;
using HMEngine.HMEffects;
using HMEngine.HMInputs;
using HMEngine.HMObjects;
using Microsoft.Xna.Framework;

namespace HMEngine {
    public sealed class HMGame : Game {
        private readonly GraphicsDeviceManager myGraphics;

        public HMGame(int width, int height) {
            myGraphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = width, PreferredBackBufferHeight = height };

            Components.Add(new HMObjectManager(this));
            Components.Add(new HMCameraManager(this));
            Components.Add(new HMEffectManager(this));
            Components.Add(new HMInputManager(this));
            Components.Add(new HMComponentManager(this));

            Window.AllowUserResizing = true;
            Window.ClientSizeChanged += Window_ClientSizeChanged;
        }

        private void Window_ClientSizeChanged(object sender, EventArgs e) {
            myGraphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
            myGraphics.PreferredBackBufferHeight = Window.ClientBounds.Height;

            HMCameraManager.ActiveCamera.Viewport = GraphicsDevice.Viewport;
        }

        public void ToggleFullScreen() { myGraphics.ToggleFullScreen(); }

        protected override void Draw(GameTime gameTime) {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);
        }
    }
}